package com.atguigu.gulimail.search.controller;

import com.atguigu.common.es.SkuEsModel;
import com.atguigu.common.utils.R;
import com.atguigu.gulimail.search.Service.ProductSaveService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;
@Slf4j
@RestController
@RequestMapping("/search/save")
public class EsSaveController {

    @Autowired
    ProductSaveService productSaveService;

    //上架商品
    @PostMapping("/product")
    public R productStatusUp(@RequestBody List<SkuEsModel> skuEsModelList) {
        boolean b=false;
        try {
            b=productSaveService.productStatusUp(skuEsModelList);
        }catch (Exception e){
            log.info("asd");
            return R.error(1111,"商品上架出现错误");
        }
        if(!b){
            return R.ok();
        }else {
            return R.error(1111,"商品上架出现错误");
        }
    }

}
